package com.zwxu.upload;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@Configuration
public class ApplicationConfig {
    @Bean
    public AmazonS3ClientInstance amazonS3ClientInstance(){
        return new AmazonS3ClientInstance("172.31.205.29:7480",
                "ewogICAgIlJHV19UT0tFTiI6ewogICAgICAgICJpZCI6ImNlcGhBZG1pbiIsCiAgICAgICAgInR5cGUiOiJsZGFwIiwKICAgICAgICAidmVyc2lvbiI6MSwKICAgICAgICAia2V5IjoiYTkwNjQ0OWQ1NzY5ZmE3MzYxZDdlY2M2YWEzZjZkMjgiCiAgICB9Cn0=",
                "cephAdmin");

        /*
        return new AmazonS3ClientInstance("192.168.19.130:7480",
                "4HI3C4C7GPHSK7TAAXCX",
                "721LMOCxGMpA1RteV0Uy8gWU1FRLXydLJ141XSVK");
                */


    }

    private CorsConfiguration buildConfig() {
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        corsConfiguration.addAllowedOrigin("*"); // 1允许任何域名使用
        corsConfiguration.addAllowedHeader("*"); // 2允许任何头
        corsConfiguration.addAllowedMethod("*"); // 3允许任何方法（post、get等）
        return corsConfiguration;
    }

    @Bean
    public CorsFilter corsFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", buildConfig()); // 4
        return new CorsFilter(source);
    }
}
